{%include file="header.html"%}
<style>
th{ text-align:left;}
</style>
<body>
<div class="fixed-bar">
  <div class="item-title">
    <h3>分类</h3>
    <a href=""><span id="abc" style="display:none;"></span></a>
    <div style="background:rgba(251,112,45,1);width:125px;height:40px;float:right;text-align:center;border-radius:5px;">
      <a href="category.php?act=edit">
        <h5 style="padding:10px;color:#fff;">添加分类</h5>
      </a>
    </div>
  </div>
</div>
<div class="fixed_bottom">
  <form method="post" action="" id="aspnetForm" name="form1">
    <table align="center;" class="table tb-type2">
      <thead>
        <tr>
          <th width="10"></th>
          <th width="50"><a>编号</a></th>
          <th width="25%"><a>分类名称</a></th>
          <th><a>上级分类</a></th>
          <th><a>商品数量</a></th>
          <th><a>排序</a></th>
          <th><a>显示</a></th>
          <th width="10%"><a>操作</a></th>
        </tr>
      </thead>
      <tbody>
      	{%foreach from=$cat_list item=list%}
      	<tr class="par_{%$list.parent_id%}" id="{%$list.cat_id%}">
          <td><span style="cursor:pointer;" onClick="on_hide(this,{%$list.cat_id%},'par_')" class="fa fa-minus-square-o"></span></td>
          <td>{%$list.cat_id%}</td>
          <td>{%$list.cat_name%}</td>
          <td>{%$list.parent_name%}</td>
          <td>{%$list.goods_num%}</td>
          <td><input style="width:30px;" onChange="sort(this,{%$list.cat_id%})" name="sort_order" type="text" value="{%$list.sort_order%}" /></td>
          <td><i onclick="ajax_show(this,{%$list.cat_id%},{%$list.is_show%})" style="cursor:pointer;" class="fa {%if $list.is_show eq 1%} fa-close {%else%} fa-check {%/if%}"></i></td>
          <td>
            <a href="category.php?act=edit&p_id={%$list.cat_id%}">添加下级</a> | 
            <a href="category.php?act=edit&c_id={%$list.cat_id%}">编辑</a> | 
            <span style="cursor:pointer;" onclick="ajax_del(this,{%$list.cat_id%})">删除</span>
          </td>
        </tr>
        {%/foreach%}
      </tbody>
    </table>
  </form>
</div>
</body>
<script>
//ajax删除商品分类
function ajax_del(obj,id){
    layer.confirm('您确认要删除这条记录吗?', {
      btn: ['确认','取消'] //按钮
    }, function(){
        $.post("category.php",{act:'ajax_del',cat_id:id},function(data){
              if(data==3){
                layer.alert("此分类不是末级分类或者此分类下还存在有商品，您不能删除！");
                return false;
              }else if(data==1){
                 layer.msg("操作成功! ");
                 $('#'+id).remove();
              }else if(data==2){
                 layer.msg("操作失败！");
              }
        });
    });
}
//排序商品分类
function sort(obj,id){
    var vals=$(obj).val();
    $.post("category.php",{act:'sort',cat_id:id,val:vals},function(data){
        if(data==1){
            window.location.reload();
        }else{
            layer.msg("操作失败！");
        }
    });
}
//ajax改变是否状态
function ajax_show(obj,id,price){
  if(price==1){
    prices="1";
  }else{
    prices="2";
  }
  $.post("category.php",{act:'ajax_show',cat_id:id,zt:prices},function(data){
      if(data==1){
      layer.msg("操作成功！");
      if(prices==1){
        $(obj).attr("onclick","ajax_show(this,"+id+",2)");
        $(obj).removeClass("fa-close");
        $(obj).addClass("fa-check");
      }else if(prices==2){
        $(obj).attr("onclick","ajax_show(this,"+id+",1)");
        $(obj).removeClass("fa-check");
        $(obj).addClass("fa-close");
      }
    }else if(data==2){
      layer.msg("操作失败！");
    }
  });  
}
</script>
</html>